/* Gyroe 1.0.0 */
/* fe_transform.c : Make the 'il' struct for executing code. */

#include <stdlib.h>
#include <string.h>
#include "fe_shared.h"
#include "fe_transform.h"

void my_int_strncpy(int *to, int *from, int len)
{
    int i;

    to[0] = len-1;

    for (i = 1;i < len;i++)
        to[i] = from[i];
}

int my_int_strlen(int *array)
{
    int i = 0;

    while (array[i] != -2)
        i++;

    return i;
}


void set_st_node(int i)
{
    int len;

    if (symtab[i][S_FILE_NO] == -2) {
        ASSIGN_TEMP_SEGMENT
        NULL_VAR_SEGMENT
        NULL_ROUTINE_SEGMENT
    }
    else if (symtab[i][S_CODE] == -2) {
        ASSIGN_TEMP_SEGMENT
        ASSIGN_VAR_SEGMENT
        NULL_ROUTINE_SEGMENT
    }
    else {
        ASSIGN_TEMP_SEGMENT
        ASSIGN_VAR_SEGMENT
        ASSIGN_ROUTINE_SEGMENT
    }
}

void create_IL()
{
    int i;

    be_symtab = malloc(st_pos * sizeof (struct symtab_entry));

    for (i = 1;i < st_pos;i++)
        set_st_node(i);

    fe_il.st   = be_symtab;
    fe_il.sl   = NULL; /// FIX!
    fe_il.misc = NULL; /// FIX!
    fe_il.lit  = NULL; /// FIX!

    my_start_backend(fe_il);
}

